package person.bing.fbcloud.leetcode;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: mengfanbing
 * @date: 2020/7/30 9:51
 */
public class Q17 {
    public static void main(String[] args) {
        String param = "23";
        List<String> stringList = letterCombinations(param);
        System.out.println(stringList);
    }
    public static List<String> letterCombinations(String digits) {
        List<String> ans = new ArrayList<>();
        if (digits.length() == 0){
            return ans;
        }
        ans.add("");
        char[] chars = digits.toCharArray();
        for (char ch:chars){
            String strByNum = getStrByNum(ch);
            if (strByNum.length() != 0){
                char[] strByNumChars = strByNum.toCharArray();
                List<String> tempAns = new ArrayList<>();
                for (char strCh:strByNumChars){
                    for (String str:ans){
                        String concat = str.concat(String.valueOf(strCh));
                        tempAns.add(concat);
                    }
                }
                ans = tempAns;
            }else {
                System.out.println("出错了");
            }
        }
        return ans;
    }
    public static String getStrByNum(char number){
        switch (number){
            case '2': return "abc";
            case '3': return "def";
            case '4': return "ghi";
            case '5': return "jkl";
            case '6': return "mno";
            case '7': return "pqrs";
            case '8': return "tuv";
            case '9': return "wxyz";
            default : return "";
        }
    }
}
